<%@ page import="com.lanqiao.guimei.vo.Product" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: stone
  Date: 2019-08-14
  Time: 21:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="../image/favicon.ico" type="image/ico"/>

    <title>贵美后台管理系统</title>

    <!-- Bootstrap -->
    <link href="../css/bootstrapcss/bootstrap.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="../css/vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="../css/vendors/nprogress/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="../css/vendors/iCheck/skins/flat/green.css" rel="stylesheet">

    <link href="../css/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-buttons-bs/css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-scroller-bs/css/scroller.bootstrap.min.css" rel="stylesheet">


    <!-- bootstrap-progressbar -->
    <link href="../css/vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet">
    <!-- JQVMap -->
    <link href="../css/vendors/jqvmap/dist/jqvmap.min.css" rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link href="../css/vendors/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="../css/build/css/custom.min.css" rel="stylesheet">

    <link href="../css/vendors/font-awesome/css/font-awesome.css" rel="stylesheet">

    <link href="../css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">

    <style>
        form div{
            margin-top: 10px;
            margin-left: 15px;
        }
        #searchBtn{
            margin-top: 10px;
        }
        #searchBtn button{
            margin-left: 20px;
        }
        #centent{
            text-align: center;
        }
        #title th{
            text-align: center;
        }
        #centent td{
            align-items: center;
            text-align: center;
        }
    </style>
</head>

<body class="nav-md">
<div class="container body">
    <div class="main_container">

        <jsp:include page="left.jsp"/>

        <!-- top navigation -->
        <jsp:include page="top.jsp"/>
        <!-- /top navigation -->

        <!-- page content -->


        <div class="right_col" role="main">
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>商品列表</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                                        <i class="fa fa-wrench"></i>
                                    </a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#">Settings 1</a>
                                        </li>
                                        <li><a href="#">Settings 2</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <div id="datatable-checkbox_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                <div class="row">
                                    <div class="col-sm-12 text-center">

                                        <form class="form-inline" action="../product/select.do" method="post">
                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon1">商品名称</span>
                                                <input type="text" class="form-control" name="prodName" placeholder="请输入名称"
                                                       aria-describedby="sizing-addon1" value="" style="width: 120px">
                                            </div>
                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon2">型号</span>
                                                <input type="text" class="form-control" name="type" placeholder="请输入型号"
                                                       aria-describedby="sizing-addon2" value="" style="width: 100px">
                                            </div>
                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon3">大类型</span>
                                                <select class="form-control" name="bigCtgr"
                                                        style="width: 100px; text-align: center"
                                                        onchange="bigTypeChange(this)">
                                                    <option value="">--请选择--</option>
                                                    <c:forEach items="${categoryList}" var="category">
                                                        <option value="${category.bigCtgr}">${category.bigCtgr}</option>
                                                    </c:forEach>
                                                </select>
                                            </div>
                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon5">供应商</span>
                                                <select class="form-control" name="venName" style="width: 100px; text-align: center">
                                                    <option value="">--请选择--</option>
                                                    <c:forEach items="${vendorList}" var="vendor">
                                                        <option value="${vendor.venName}">${vendor.venName}</option>
                                                    </c:forEach>
                                                </select>
                                            </div>

                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon7">价格</span>
                                                <input type="text" class="form-control" name="price" placeholder="起始价格"
                                                       aria-describedby="sizing-addon2" value="" style="width: 75px">
                                               <p style="float: left; margin:3px">-</p>
                                                <input type="text" class="form-control" name="price" placeholder="结束价格"
                                                       aria-describedby="sizing-addon2" value="" style="width: 75px">
                                            </div>

                                            <div class="col-sm-12 text-center" id="searchBtn">
                                                <button type="submit" class="btn btn-primary btn-sm">查询</button>
                                                <button type="reset" class="btn btn-default btn-sm">重置</button>
                                            </div>
                                        </form>
                                        <%--<form class="form-horizontal">--%>
                                            <%--<div class="form-group">--%>
                                                <%--<label for="inputEmail3" class="col-sm-2 control-label">Email</label>--%>
                                                <%--<div class="col-sm-10">--%>
                                                    <%--<input type="email" class="form-control" id="inputEmail3" placeholder="Email">--%>
                                                <%--</div>--%>
                                            <%--</div>--%>
                                        <%--</form>--%>
                                        <%--<div id="datatable-keytable_filter" class="dataTables_filter">--%>
                                            <%--<label>--%>
                                                <%--Search:<input type="search" class="form-control input-sm" placeholder="" aria-controls="datatable-keytable">--%>
                                            <%--</label>--%>
                                        <%--</div>--%>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="table-responsive" style="margin-top: 10px">
                                            <table class="table table-striped table-bordered table-hover" >
                                                <thead>
                                                <tr id="title">
                                                    <th>图片</th>
                                                    <th>商品名称</th>
                                                    <%--<th>商品编号</th>--%>
                                                    <th>类型</th>
                                                    <th>供应商</th>
                                                    <th>库存</th>
                                                    <th>价格</th>
                                                    <th>型号</th>
                                                    <th>描述</th>
                                                    <th>操作</th>
                                                </tr>
                                                </thead>

                                                <tbody>
                                                <c:forEach var="product" items="${requestScope.products}">
                                                <tr id="centent">
                                                    <td style="width: 110px;padding: 10px">

                                                        <img src="../${product.image}" alt="" width="80px" height="80px">
                                                    </td>
                                                    <td>${product.prodName}</td>
                                                    <%--<td>${product.prodNo}</td>--%>
                                                    <td>${product.type}</td>
                                                    <td>${product.vendor.venName}</td>
                                                    <td>${product.stock.quantity}</td>
                                                    <td>${product.price}</td>
                                                    <td>${product.type}</td>
                                                    <td>
                                                        <p style="width: 120px">
                                                                ${product.descr}
                                                        </p>
                                                    </td>
                                                    <td>
                                                        <a class="btn btn-xs btn-info" data-toggle="modal" data-target="#updatePro"
                                                           data-backdrop="static"  onclick="toUpdateProduct('${product.prodNo}')">
                                                            <span class="glyphicon glyphicon-refresh"></span>更新</a>
                                                        <c:if test="${product.remark eq 0}" >
                                                            <a class="demo4 btn btn-xs btn-primary" prodNo="${product.prodNo}"
                                                           data-toggle="modal" data-target="#productSale" data-backdrop="static" onclick="toProductSale('${product.prodNo}')"
                                                        >上架</a></c:if>
                                                        <c:if test="${product.remark eq 1}" ><a class="btn btn-xs btn-info">已上架</a></c:if>
                                                       <%-- <a href="javascript:void(0)"  class="btn btn-primary btn-sm">
                                                            <span class="glyphicon glyphicon-edit">更新</span>
                                                        </a>
                                                        <a href="" class="btn btn-danger btn-sm">
                                                            <span class="glyphicon glyphicon-trash">删除</span>
                                                        </a>--%>
                                                    </td>
                                                </tr>
                                                </c:forEach>

                                                </tbody>

                                                <tr>
                                                    <td colspan="10" class="text-right">
                                                        <c:if test="${ not productPage.first}">
                                                            <a href="../product/select.do?pageNo=1">第一页</a>
                                                        </c:if>
                                                        <c:if test="${productPage.pageNo gt 1}">
                                                            <a href="../product/select.do?pageNo=${productPage.pageNo-1}">上一页</a>
                                                        </c:if>
                                                        <c:if test="${productPage.pageNo lt productPage.totalPage}">
                                                            <a href="../product/select.do?pageNo=${productPage.pageNo+1}">下一页</a>
                                                        </c:if>
                                                        <c:if test="${ not productPage.last}">
                                                            <a href="../product/select.do?pageNo=${productPage.lastIndex}">最后一页</a>
                                                        </c:if>
                                                        <c:if test="${ not empty productPage}">
                                                            <a>&nbsp;&nbsp;&nbsp;总共${productPage.totalRow}条记录；第${productPage.pageNo}页/总共${productPage.totalPage}页</a>
                                                        </c:if>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <%--更新操作的模态框--%>
        <div class="modal fade" tabindex="-1" role="dialog" id="updatePro">
            <div class="modal-dialog" role="document">
                <div class="modal-content">

                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

        <%--更新操作的模态框--%>
        <div class="modal fade" tabindex="-1" role="dialog" id="productSale">
            <div class="modal-dialog" role="document">
                <div class="modal-content">

                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->


        <!-- /page content -->

        <!-- footer content -->
        <%--<footer>--%>
        <%--<div class="pull-right">--%>
        <%--Gentelella - Bootstrap Admin Template by <a href="https://colorlib.com">Colorlib</a>--%>
        <%--</div>--%>
        <%--<div class="clearfix"></div>--%>
        <%--</footer>--%>
        <!-- /footer content -->
    </div>
</div>

<!-- jQuery -->
<script src="../js/jquery-2.2.4.js"></script>
<!-- Bootstrap -->
<script src="../js/bootstrap.js"></script>
<!-- FastClick -->
<script src="../css/vendors/fastclick/lib/fastclick.js"></script>
<!-- NProgress -->
<script src="../css/vendors/nprogress/nprogress.js"></script>
<!-- Chart.js -->
<script src="../css/vendors/Chart.js/dist/Chart.min.js"></script>
<!-- gauge.js -->
<script src="../css/vendors/gauge.js/dist/gauge.min.js"></script>
<!-- bootstrap-progressbar -->
<script src="../css/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
<!-- iCheck -->
<script src="../css/vendors/iCheck/icheck.min.js"></script>
<!-- Skycons -->
<script src="../css/vendors/skycons/skycons.js"></script>
<!-- Flot -->
<script src="../css/vendors/Flot/jquery.flot.js"></script>
<script src="../css/vendors/Flot/jquery.flot.pie.js"></script>
<script src="../css/vendors/Flot/jquery.flot.time.js"></script>
<script src="../css/vendors/Flot/jquery.flot.stack.js"></script>
<script src="../css/vendors/Flot/jquery.flot.resize.js"></script>
<!-- Flot plugins -->
<script src="../css/vendors/flot.orderbars/js/jquery.flot.orderBars.js"></script>
<script src="../css/vendors/flot-spline/js/jquery.flot.spline.min.js"></script>
<script src="../css/vendors/flot.curvedlines/curvedLines.js"></script>
<!-- DateJS -->
<script src="../css/vendors/DateJS/build/date.js"></script>
<!-- Datatables -->
<script src="../css/vendors/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../css/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
<script src="../css/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
<script src="../css/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
<script src="../css/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
<script src="../css/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
<script src="../css/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
<script src="../css/vendors/datatables.net-scroller/js/dataTables.scroller.min.js"></script>
<script src="../css/vendors/jszip/dist/jszip.min.js"></script>
<script src="../css/vendors/pdfmake/build/pdfmake.min.js"></script>
<script src="../css/vendors/pdfmake/build/vfs_fonts.js"></script>
<!-- JQVMap -->
<script src="../css/vendors/jqvmap/dist/jquery.vmap.js"></script>
<script src="../css/vendors/jqvmap/dist/maps/jquery.vmap.world.js"></script>
<script src="../css/vendors/jqvmap/examples/js/jquery.vmap.sampledata.js"></script>
<!-- bootstrap-daterangepicker -->
<script src="../css/vendors/moment/min/moment.min.js"></script>
<script src="../css/vendors/bootstrap-daterangepicker/daterangepicker.js"></script>

<!-- Custom Theme Scripts --><%--
<script src="../css/build/js/custom.min.js"></script>--%>

<script>

    function bigTypeChange(ele) {
        var bigType = $(ele).val();
        $.ajax({
            type: 'post',
            url:'',
            data: {
                bigType: bigType
            },
            dataType: 'json',
            success: function (res) {
                var littleTypeSelect = $('#littleType');
                res.forEach(function (type) {
                    var option = new Option(type.name, type.number);
                    littleTypeSelect.append(option);
                })
            }
        })
    }
</script>


<script src="../js/jquery-2.2.4.js"></script>
<script src="../js/bootstrap.js"></script>
<!-- Mainly scripts -->
<script src="../js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="../js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

<!-- Custom and plugin javascript -->
<script src="../js/inspinia.js"></script>
<script src="../js/plugins/pace/pace.min.js"></script>

<!-- Sweet alert -->
<script src="../js/plugins/sweetalert/sweetalert.min.js"></script>
<script>
   /* // 上架弹出框
    $('.demo4').click(function () {

        // 获取a中empno属性的值
        var prodNo=$(this).attr('prodNo');
        //console.log($(this).attr('prodNo'));
        swal({
                title: "你确定将"+prodNo+"商品信息上架?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的，立马上架！",
                cancelButtonText: "取消，再想想",
                closeOnConfirm: false,
                closeOnCancel: false },
            function (isConfirm) {
                if (isConfirm) {
                    putaway(prodNo);
                    swal("上架", "该商品"+prodNo+"信息已经上架", "success");
                } else {
                    swal("取消", "该商品"+prodNo+"信息上架操作被取消)", "error");
                }
            });
    });

    // 上架操作
    function putaway(prod_no) {
        // 通过get发送信息到
        $.get('../product/doPutaway.do',{prodNo:prod_no},
            function (res) {
                if (res.result){
                    console.log(res.result);
                }
            },'json')
    }*/


    // 将表单加入到模态框中显示，查询显示需要更新的数据
   /* function update(prod_no) {

        // 在加入表单到模态框前先清除模态框内之前的表单
        $('#updatePro .modal-content').empty();

        $.get('updateProductForm.jsp',{prodNo: prod_no},function (res) {
            console.log(res);
            $('#updatePro.modal-content').html(res);
        },'html')
    }*/
    function toProductSale(prod_no) {

        // 在加入表单到模态框前先清除模态框内之前的表单
        $('#productSale .modal-content').empty();

        $.get('../product/selectSaleProd.do?prodNo='+prod_no,function (res) {
            //console.log(res);
            $('#productSale .modal-content').html(res);
        },'html');
    }

   // 上架操作
   function putaway(prod_no) {
       // 通过get发送信息到
       $.get('../product/doPutaway.do',{prodNo:prod_no},
           function (res) {
               if (res.result){
                   console.log(res.result);
               }
           },'json')
   }

    function toUpdateProduct(prod_no) {

        // 在加入表单到模态框前先清除模态框内之前的表单
        $('#updatePro .modal-content').empty();

        $.get('../product/selectById.do?prodNo='+prod_no,function (res) {
            //console.log(res);
            $('#updatePro .modal-content').html(res);
        },'html');
    }

    // 更新保存
    function updateSave(prodNo) {
        //console.log(prodNo);
        // 序列化表单
        var data = $('#updateProduct').serialize();
        //console.log(data);
        $.post('../product/doUpdate.do',data,function (res) {
            //console.log("123");
            if (res.result){
                //console.log(res.result);

                // 手动关闭模态框
                $('#updateProduct').modal('hide');
                $('#updateProduct.modal-content').empty();
                swal({
                    title: "更新商品",
                    text: "更新"+prodNo+"的商品信息成功",
                    type: "success"
                },function () {
                    location.reload();
                });

            } else {
                swal({
                    title: "更新商品",
                    text: "更新"+prodNo+"的商品信息失败，请重新检查",
                    type:"error"
                });
            }
        },'json')

    }
</script>

</body>
</html>